//
//  mainVC.m
//  dataGathering
//
//  Created by apple on 14-11-4.
//  Copyright (c) 2014年 shuili. All rights reserved.
//

#import "mainVC.h"
#import "rightSubTItleVC.h"
#import "MapMainView.h"

@interface mainVC ()

@end

@implementation mainVC
@synthesize state;
@synthesize previousState;

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    state = MainVCStateMyCollection;
    previousState = MainVCStateNewCollection;
    
    [[NSUserDefaults standardUserDefaults] setObject:@"NO" forKey:@"isRecordingGeometry"];
    
    [self refreshRightSubView];
    
    UITableViewController *taskCollectionTableVC = (UITableViewController*)[[((UIViewController *)[[self childViewControllers] objectAtIndex:0]) childViewControllers] objectAtIndex:0];
    
    //taskCollectionTableVC.tableView.delegate = self;
    if([taskCollectionTableVC.tableView numberOfRowsInSection:0] > 0){
        
    }
    // Do any additional setup after loading the view.
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

-(void)addNewTaskCollection
{
    if(state == MainVCStateNewCollection){
        return;
    }
    previousState = state;
    state = MainVCStateNewCollection;
    [self refreshRightSubView];
    rightSubTitleVC *vc = (rightSubTitleVC*)[[self childViewControllers] objectAtIndex:1];
    [vc toAddNewTaskCollectionView];
    
    
    
}

-(void)removeNewTaskCollectionView
{
    rightSubTitleVC *vc = (rightSubTitleVC*)[[self childViewControllers] objectAtIndex:1];
    [vc removeAddNewTaskCollectionView];
    state = previousState;
}

-(void)refreshRightSubView
{
    rightSubTitleVC *vc = (rightSubTitleVC*)[[self childViewControllers] objectAtIndex:1];
    [vc reloadButtons];
}

-(void)openDetailMapView
{
    [self performSegueWithIdentifier:@"toTaskCollectionMapView" sender:nil];
}


 #pragma mark - Navigation
 
 // In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
    NSLog(@"%@", [segue identifier]);
    if([segue identifier] == nil){
        return;
    }
    if([[segue identifier] compare:@"toTaskCollectionMapView"] == NSOrderedSame){
        currentWorkSetManager *worksetMgr = [currentWorkSetManager sharedInstance];
        workSet *currentWorkset = [worksetMgr getCurrentWorkSet];
       MapMainView* mapMainVC = (MapMainView*)[segue destinationViewController];
        [mapMainVC setCollectionTitle:[currentWorkset name]];
    }
}

#pragma UITableViewDelegate
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{

}


@end
